package com.sxt.bus.controller;

import com.sxt.bus.domain.ChargeRule;
import com.sxt.bus.service.ChargeRuleService;
import com.sxt.bus.vo.ChargeRuleVo;
import com.sxt.sys.constant.SYSConstant;
import com.sxt.sys.utils.ResultObj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author WanMing
 * @date 2019/2/10 20:28
 */

@Controller
@RequestMapping("chargeRule")
public class ChargeRuleController {

    @Autowired
    private ChargeRuleService chargeRuleService;


    /**
     * 加载所有的数据
     * @param chargeRuleVo
     * @return
     */
    @RequestMapping("loadAllChargeRule")
    @ResponseBody
    public List<ChargeRule> loadAllCharge(ChargeRuleVo chargeRuleVo){
       return  chargeRuleService.queryAllChargeRule(chargeRuleVo);
    }

    /**
     * 修改
     * @param chargeRuleVo
     * @return
     */
    @RequestMapping("updateChargeRule")
    @ResponseBody
    public ResultObj updateChargeRule(ChargeRuleVo chargeRuleVo){
        ResultObj resultObj = null;
        try {
            chargeRuleService.updateChargeRule(chargeRuleVo);
            resultObj = new ResultObj(SYSConstant.SUCCESS_CODE,SYSConstant.UPDATE_SUCCESS);
        } catch (Exception e) {
            e.printStackTrace();
            resultObj = new ResultObj(SYSConstant.ERROR_CODE,SYSConstant.UPDATE_ERROR);
        }
        return  resultObj;
    }


}
